package com.jokerpan.project.Message;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author jokerpan
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Msg {
    //错误码
    int code;
    //消息提示
    String Message;
    //数据
    Map<String,Object> data=new HashMap<String,Object>();

    //无权访问
    public static Msg denyAccess(String message){
        Msg result=new Msg();
        result.setCode(300);
        result.setMessage(message);
        return result;
    }

    //操作成功
    public static Msg success(String message, String token){
        Msg result=new Msg();
        Map<String, Object> map = new HashMap<>();
        map.put("token", token);
        result.setData(map);
        result.setCode(200);
        result.setMessage(message);
        return result;
    }

    public static Msg success(String message, Map map){
        Msg result=new Msg();
        result.setData(map);
        result.setCode(200);
        result.setMessage(message);
        return result;
    }

    public static Msg success(String message){
        Msg result=new Msg();
        result.setCode(200);
        result.setMessage(message);
        return result;
    }

    //客户端操作失败
    public static Msg fail(String message){
        Msg result=new Msg();
        result.setCode(400);
        result.setMessage(message);
        return result;
    }

    public Msg add(String key,Object value){
        this.data.put(key,value);
        return this;
    }
}
